//
//  MovieDoc.swift
//  Studio Media Player
//
//  Created by DannyNiu on 2025-09-09.
//

import Cocoa
import Foundation
import AVFoundation

class MovieDoc: NSDocument {
    
    @IBOutlet var appd: AppDelegate!
    /*
    override var windowNibName: String? {
        // Override returning the nib file name of the document
        // If you need to use a subclass of NSWindowController or if your document supports multiple NSWindowControllers, you should remove this method and override -makeWindowControllers instead.
        return "MovieDoc"
    }
    */

    override func windowControllerDidLoadNib(_ aController: NSWindowController) {
        super.windowControllerDidLoadNib(aController)
        // Add any code here that needs to be executed once the windowController has loaded the document's window.
    }

    override func data(ofType typeName: String) throws -> Data {
        // Insert code here to write your document to data of the specified type, throwing an error in case of failure.
        // Alternatively, you could remove this method and override fileWrapper(ofType:), write(to:ofType:), or write(to:ofType:for:originalContentsURL:) instead.
        throw NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil)
    }
    
    override func read(from url: URL, ofType typeName: String) throws {
        // Insert code here to read your document from the given data of the specified type, throwing an error in case of failure.
        // Alternatively, you could remove this method and override read(from:ofType:) instead.  If you do, you should also override isEntireFileLoaded to return false if the contents are lazily loaded.
        Task.detached {
            let ass: AVURLAsset = .init(url: url)
            await self.appd.mvv.assign_asset(ass)
            await self.appd.mvv.player?.play()
            NSCursor.setHiddenUntilMouseMoves(true)
        }
        
    }
    
    override class var autosavesInPlace: Bool {
        return true
    }

}
